#include "base/log.h"
#include <sys/time.h>
#include <sys/timerfd.h>
#include <stdlib.h>
#include <unistd.h>

#include "base/timer.h"
namespace net_tools::base{

Timer::Timer()
  :timefd_(timerfd_create(CLOCK_REALTIME,TFD_NONBLOCK | TFD_CLOEXEC))
{
  interval_.tv_nsec = 0;
  interval_.tv_sec = 0;
};
Timer::~Timer(){
  close(timefd_);
  NT_LOG_INFO << "Timer close" << NT_LOG_ENDL;
}
void Timer::Settime(timeval value){
  itimerspec itimer_;
  itimer_.it_value.tv_sec = value.tv_sec;
  itimer_.it_value.tv_nsec = value.tv_usec * 1000 + 1;
  itimer_.it_interval = interval_;
  timerfd_settime(timefd_,CLOCK_REALTIME,&itimer_,NULL);
};

} // namespace net_tools::base